<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category NewController.php
 * @Depiction:
 * Author: hwy
 * Date: 2021/2/7  15:21
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Index;

use App\Http\Controllers\Controller;
use App\Models\CollectArticle;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class NewController extends Controller
{

    public function index(Request $request)
    {
        $cache_name = 'number_collect_article';
        $cache_ttl = Carbon::now()->addSeconds(20);
        $number = Cache::remember($cache_name, $cache_ttl, function () {
            return $number = CollectArticle::getNumber();
        });
        $compact = compact('request', 'number');
        return view('index.news.index', $compact);
    }

    public function show(Request $request)
    {
        $list = CollectArticle::getList($request);
        $list = $list['data'];
        $compact = compact('list');

        $html = view('index.news._section', $compact)->render();
        $data['html'] = $html;
        $data['last_page'] = $list['last_page'];
        return response()->json(['code' => 1, 'data' => $data]);
    }

}
